//$(function(){

	var currentPage;
	var prices = Array();
	var orders_total = Array();
	var orders_total_result = 0;
	var orders = Array();//存放购物车、订单的菜对应的ID（除土特团之外的才，一样菜只能买一道）
	var tutetuans = Array();//存放购物车、订单的菜对应的ID（只对应土特团的菜，因为这个有数量）
	var history = Array();	//记录访问的历史顺序
	
	history.push({
		url: window.location,
		page: 'home',
		id: '#home-items',
		header: '#home-header',
		time: new Date()
	});
	
	var baseUrl = "http://112.124.41.175/maicai/";//$("base").attr("href")
	
	function alert2(myText){
		$("#dialog #text").text(myText);
		$("#dialog").css("display","block");
		setTimeout(function(){
				$("#dialog").hide();
			},800
		);
	}
	
	function _count(){
		var count = 0;
		for(var i in tutetuans){
			if(tutetuans[i] != -1)
				count++;
		}
		for(var i in orders){
			if(orders[i] != -1)
				count++;
		}
		return count;
	}
	
	//土特团详情页面
	function tuanDetailGet(id){
		var url = $("base").attr("href")+'ajax/tuanDetailGet/'+id;
		$.ajax({
			url: url,
			success: function(data){
				var data = eval("("+ data +")");
				$("#detail-header-name").text(data.name);
				/**
				 * 区分是否为图特团
				 */
				$("#detail-header-name").attr("name", "tutetuan")
				$("#detail-item-id").val(data.id);
				var detailItem = $("#detail-item");
				detailItem.find("#detail-item-img").attr("src", data.picurl);
				detailItem.find("#detail-1").text("价格");
				detailItem.find("#detail-2").text("配送时间");
				detailItem.find("#detail-3").text("开团人数");
				detailItem.find("#detail-4").hide();
				detailItem.find("#detail-5").text("详情");

				detailItem.find("#detail-item-img").attr("src", data.picurl);
				detailItem.find(".tuan_price").text(data.price+data.unit);//\n8月6日-8月13日优惠价20元/盒");//data.price.replace(/[^0-9]/ig,"")+"元/盒(10个)");
				detailItem.find("#volume").text(data.time);
				detailItem.find("#material").text(data.number+'人起团');
				//detailItem.find("#submaterial").text(data.submaterial);
				detailItem.find("#practice").html(data.content);//.replace(/\n/g,'<br>'));

			}
		});
	}

	//普通列表详情页面
	function itemDetailGet(id){
		var url = $("base").attr("href")+'ajax/itemDetailGet/'+id;
		$.ajax({
			url: url,
			success: function(data){
				//console.log(data);
				var data = eval("("+ data +")");
				$("#detail-header-name").text(data.name);
				$("#detail-item-id").val(data.id);
				var detailItem = $("#detail-item");
				detailItem.find("#detail-1").text("价格:");
				detailItem.find("#detail-2").text("分量:");
				detailItem.find("#detail-3").text("主料:");
				detailItem.find("#detail-4").show();
				detailItem.find("#detail-5").text("做法:");
				
				detailItem.find("#detail-item-img").attr("src", data.picurl);
				detailItem.find("#price").text(data.price.replace(/[^0-9]/ig,"")+"元");
				detailItem.find("#volume").text(data.volume+"人份");
				var material = "";
				for(var d in data.main){
					material += data.main[d].material + " ";
				}
				detailItem.find("#material").text(material);
				detailItem.find("#submaterial").text(data.submaterial);
				detailItem.find("#practice").html(data.practice.replace(/\n/g,'<br>'));
			}
		});
	}
	
	//在购物车页面，点击“-减号”事件
	$(document).on("click", ".item .minus", function(){
		var number = parseInt($("#"+$(this).attr("name")).text())-1;
		if(number >= 1){
			$("#"+$(this).attr("name")).text(number);
		}
		else 
			return ;
		var id = $(this).attr("name").split("numberofid")[1];
		var current_price = parseInt($("#tuan-all").text());
		$("#tuan-all").text(current_price-parseInt($("#priceofid"+id).val()));
		//$("#tuan-all").text(number*parseInt($("#priceofid"+id).val()));
	});
	
	//在购物车页面，点击“+加号”事件
	$(document).on("click", ".item .plus", function(){
		var number = parseInt($("#"+$(this).attr("name")).text())+1;
		if(number >= 1){
			$("#"+$(this).attr("name")).text(number);
		}
		else
			return ;
		var id = $(this).attr("name").split("numberofid")[1];
		var current_price = parseInt($("#tuan-all").text());
		//alert(current_price-parseInt($("#priceofid"+id).val()));
		$("#tuan-all").text(current_price+parseInt($("#priceofid"+id).val()));
		
	});
	
	/**
	 * Get请求购物车详情
	 */
	function cartDetailGet(){
		$("#in-cart-items div").remove();
		$("#in-tuan-items div").remove();
		$("#amount_1").hide();
		$("#amount_2").hide();
		var wechat_id = $("#wechat_id").val();
		var url = $("base").attr("href")+'ajax/cartDetailGet/'+wechat_id;
		//console.log(tutetuans);
		$.ajax({
			url: url,
			data: { ids: orders , tuan_ids: tutetuans},
			success: function(data){
				//console.log(data);
				var data = eval("("+data+")");
				// 计算图特团
				var tuan = data.tutetuans;
				var cartItems = "";
				var total = 0;
				if(tuan){
					prices = Array();
					for(var i in tuan){
						var item = '<div class="item" name="tutetuan">'
							+ '<input id="priceofid'+tuan[i].id+'" type="hidden" value="'+ tuan[i].price.replace(/[^0-9]/ig,"") +'"/>'
							+ '<img src="'+ tuan[i].picurl +'" />'
							+ '<div class="info" name="tutetuan">'
							+ '<span style="font-size:14px;">' + tuan[i].name +'&nbsp;&nbsp;' + tuan[i].price.replace(/[^0-9]/ig,"") +'元 ('+tuan[i].time+'配送)</span>'
							//+ '<span class="name" style="padding:12px 5px 0px 0">'+ tuan[i].name+'&nbsp;&nbsp;<p style="float:right;padding:0;margin:0;padding-top:5px;">'+tuan[i].time+'配送</p></span>'
							//+ '<span class="price" style="margin:0;padding:0">'+ tuan[i].price.replace(/[^0-9]/ig,"") +'元 '+ tuan[i].number +'人起团</span>'
							+ '<a name="'+tuan[i].id+'" class="item-remove delete" style="margin-top:5px">删除</a>'
							+ '<span style="width:120px;display:inline-block;margin-top:5px;"><button name="numberofid'+tuan[i].id+'" class="minus">-</button>&nbsp;&nbsp;<label style="display:inline-block" id="numberofid'+tuan[i].id+'" style="width:20px;">1</label>&nbsp;&nbsp;<button name="numberofid'+tuan[i].id+'"class="plus">+</button></span>'
							+ '</div>'
							+ '<div class="border"></div></div>';
						cartItems += item;
						total += parseFloat(tuan[i].price.replace(/[^0-9]/ig,""));
						prices.push(tuan[i].price.replace(/[^0-9]/ig,""));
					}
					$("#in-tuan-items").append(cartItems);
					$("#amount_2").show();
				}
				$("#tuan-all").text(total);
				var discount = data.discount;
				var count = data.count;
				data = data.data;
				var total = 0;
				if(data){
					var cartItems = "";
					prices = Array();
					for(var i in data){
						var item = '<div class="item">'
							+ '<a name="'+data[i].Cookbook.id+'" class="item-remove delete">删除</a>'
							+ '<input id="priceofid'+data[i].Cookbook.id+'" type="hidden" value="'+ data[i].Material.price.replace(/[^0-9]/ig,"") +'"/>'
							+ '<img src="'+ data[i].Material.picurl +'" />'
							+ '<div class="info">'
							+ '<span class="name">'+ data[i].Material.name+'</span>'
							+ '<span class="price">'+ data[i].Material.price.replace(/[^0-9]/ig,"") +'元 '+ data[i].Material.volume +'人份</span>'
							+ '</div>'
							+ '<div class="border"></div></div>';
						cartItems += item;
						total += parseFloat(data[i].Material.price.replace(/[^0-9]/ig,""));
						prices.push(data[i].Material.price.replace(/[^0-9]/ig,""));
					}
					$("#in-cart-items").append(cartItems);
					if(new Date().getTime() <= 1374000000000){
						/**
						 * 原满三免一逻辑
						 */			
						prices.sort(function(x,y){return parseFloat(y)-parseFloat(x);}); 
						//console.log(prices.length/3);
						total = 0;
						var total_all = 0;
						var j = 0;
						for(var i in prices){
							total_all += parseFloat(prices[i]);
							if(j++ < prices.length - (prices.length/3)){
								total+= parseFloat(prices[i]);
							}
						}
						//console.log(prices);
						var counter = 0;
						for(var i in orders){
							counter ++;
						}
						if(counter >= 3){
							$("#cart-items .advanced").text("满三免一");
						}
						else {
							$("#cart-items .advanced").text("购满三件菜品，即可享受满三免一优惠．");
						}
						$("#cart-items #total").text(total);
						$("#cart-items #total-all").text(total_all);
						console.log(total);
						console.log(total_all);
					}
					else {
						/**
						 * 新用户下单，减五元
						 */
						$("#cart-items #total-all").text(total);
						$("#cart-items .advanced").hide();
						/*
						if(count <= 0){
							$("#cart-items #total").text(total-5);
							$("#cart-items #total-all").text(total);
							if(total-5 >= 25)
								$("#cart-items .advanced").text("(享受新用户立减5元并获得6元优惠券下次使用)");
							else 
								$("#cart-items .advanced").text("(第一次下单, 立减五元)");
							$("#cart-items .advanced").show();
						}
						else 
						*/
						
						// 日期：20130819 之后优惠券暂时不发放 时间戳： 1376928000000
						var youhuiquan_end_date = 1376928000000;
						$("#cart-items #total").text(total);
						
						if(discount == 1){
							$("#cart-items #total").text(total-6);
							$("#cart-items #total-all").text(total);
							$("#cart-items .advanced").text("(使用6元优惠券一张)");
							$("#cart-items .advanced").show();
						}
						// 日期：20130819 之后优惠券暂时不发放 时间戳： 1376928000000
						else if(total >= 25 && new Date().getTime() < youhuiquan_end_date){
							$("#cart-items #total").text(total);
							$("#cart-items .advanced").text("(获得6元优惠券一张)");
							$("#cart-items .advanced").show();
						}
						else if(new Date().getTime() < youhuiquan_end_date){
							$("#cart-items #total").text(total);
							$("#cart-items .advanced").text("(消费满25元即可获得6元优惠券一张下次使用)");
							$("#cart-items .advanced").show();	
						}
					}
					$("#amount_1").show();
				}
			}
		});
	}
	
	function clearShadow(){
		$(".home-shadow").remove();
	}
	
	//在列表页面，点击图片，选中效果，加入购物车
	function setShadow(){
		$(".home-shadow").remove();
		$("#home-items div#i").each(function(i, el){
			var heightGap = 30;
			var id = $(this).parent().attr("name");
			if($(el).hasClass("special") || $(el).hasClass("recommend")){
				heightGap = 80;
			}
			
			//alert($(".types .active").attr("name"));
			if($(".types .active").attr("name") == "3"){
				if(tutetuans[$(el).attr("name")] == $(el).attr("name")){
					var img = $(el).find(".item-image");
					$(el).append(
						'<div id="shadow'+ $(el).attr("name") +'" class="home-shadow"style="position:absolute; '+
						'width: '+ img.offset().width +'px; '+
						'height: '+ (img.offset().height-heightGap)+'px;'+
						'left: '+ img.offset().left +'px; '+
						'top: '+ img.offset().top +'px;'+ 
						'padding-top: '+heightGap+'px">' +
						'<div><img src="'+$("base").attr("href")+'images/check.png"/>&nbsp;&nbsp;已选</div></div>'
					);
				}
			}
			else {
				if(orders[$(el).attr("name")] == $(el).attr("name")){
					var img = $(el).find(".item-image");
					$(el).append(
						'<div id="shadow'+ $(el).attr("name") +'" class="home-shadow"style="position:absolute; '+
						'width: '+ img.offset().width +'px; '+
						'height: '+ (img.offset().height-heightGap)+'px;'+
						'left: '+ img.offset().left +'px; '+
						'top: '+ img.offset().top +'px;'+ 
						'padding-top: '+heightGap+'px">' +
						'<div><img src="'+$("base").attr("href")+'images/check.png"/>&nbsp;&nbsp;已选</div></div>'
					);
				}
			}
		});
	}
	
	//下单成功
	function orderResultSet(data){
		//alert("下单成功");
		//alert(data.msg);
		$("#report-page #time").text(data.time);
		var price = 0;
		var counter = 0;
		prices = Array();
		console.log(data);
		$(".report").hide();
		if(data.discount >= 0){
			$(".report").show();
		}
		
		$(".report-orders p").remove();
		for(var i in data.material){
			counter ++;
			$("#report-page .report-orders").append("<p>"+
				counter + "、"+ data.material[i].name +"(" +
				data.material[i].volume +"人份) "+
				data.material[i].price.replace(/[^0-9]/ig,"") +"元"+"</p>")
			prices.push(parseFloat(data.material[i].price.replace(/[^0-9]/ig,"")));
			price += parseFloat(data.material[i].price.replace(/[^0-9]/ig,""));
		}
		prices.sort(function(x,y){return parseFloat(y)-parseFloat(x);}); 
		//console.log(prices.length/3);
				
		if(new Date().getTime() <= 1374000000000){
			total = 0;
			var recieved_price = 0;
			var j = 0;
			for(var i in prices){
				recieved_price += parseFloat(prices[i]);
				if(j++ < prices.length - (prices.length/3)){
					total+= parseFloat(prices[i]);
				}
			}
			$("#report-page #price").text(recieved_price);
			$("#report-page #recieved-price").text(total);
		}
		else {
		/*
			if(data.count > 0){
				if(data.cart.discount_id == 0){
					$("#report-page #price").text(price);
					$("#report-page #recieved-price").text(price);
				}
				else {
					$("#report-page #price").text(price);
					$("#report-page #recieved-price").text(price-6);
				}
			}
			else {
				$("#report-page #price").text(price);
				$("#report-page #recieved-price").text(price-5);
			}
		*/
			var count = data.count;
			var discount = data.discount;
			var total =  price;
			/* 新用户下单免5元逻辑
			if(count <= 0){
				$("#report-page #price").text(total);
				$("#report-page #recieved-price").text(total-5);
				if(total-5 >= 25)
					$("#report-page .report-advanced").text("(享受新用户立减5元并获得6元优惠券下次使用)");
				else 
					$("#report-page .report-advanced").text("(第一次下单, 立减五元)");
				$("#report-page .report-advanced").show();
			}
			else 
			*/
			
			// 日期：20130819 之后优惠券暂时不发放 时间戳： 1376928000000
			var youhuiquan_end_date = 1376928000000;
			$("#report-page #price").text(total);
			if(discount == 1){
				$("#report-page #price").text(total);
				$("#report-page #recieved-price").text(total-6);
				$("#report-page .report-advanced").text("(使用6元优惠券一张)");
				$("#report-page .report-advanced").show();
			}
			else if(total >= 25 && new Date().getTime() < youhuiquan_end_date){
				$("#report-page #price").text(total);
				$("#report-page #recieved-price").text(total);
				$("#report-page .report-advanced").text("(获得6元优惠券一张)");
				$("#report-page .report-advanced").show();
			}
			else if(new Date().getTime() < youhuiquan_end_date) {
				$("#report-page #price").text(total);
				$("#report-page #recieved-price").text(total);
				$("#report-page .report-advanced").text("(消费满25元即可获得6元优惠券一张下次使用)");
				$("#report-page .report-advanced").show();	
			}
			else {
				$("#report-page #price").text(total);
				$("#report-page #recieved-price").text(total);
				$("#report-page .report-advanced").show();	
			}
		}
		$(".report_tuan").hide();
		$(".report_tuan").children().remove();
		if(data.tutetuan && data.tutetuan.length > 0){
			$(".report_tuan").show();
			var tuan = data.tutetuan;
			for(var i in tuan){
				var tuan_price = parseInt(tuan[i].fenliang)*parseInt(tuan[i].price);
				var tmp = '<p class="report-message">您于<span id="time">'+tuan[i].create_time+'</span>参与土特团:</p>'+
							'<p style="margin-left:15px">'+tuan[i].name+' '+tuan[i].price+'元*'+tuan[i].fenliang+' ('+tuan[i].time+'配送)</p>'+
							'<div style="text-align: right;padding: 10px;text-align: right;color: green;font-size: 15px;font-weight: bold;">合计'+tuan_price+'元, 总价:'+tuan_price+'元</div>';
				$(".report_tuan").append(tmp);
			}
		}
	}
	
	//去掉或显示阴影效果（点击图片的时候）
	function shadow(){
		var self = this;
		var heightGap = 30;
		var id = $(this).parent().attr("name");
		if($(this).parent().hasClass("special") || $(this).parent().hasClass("recommend")){
			heightGap = 80;
		}
		
		if($(".types .active").attr("name") == 3){
			if(tutetuans[id] > 0){
				tutetuans[id] = -1;
				$("div #shadow"+id).remove();
			}
			else {
				tutetuans[id] = id;
				//console.log(tutetuans);
				$(self).parent().append(
					'<div id="shadow'+ id +'" class="home-shadow"style="position:absolute; '+
					'width: '+ self.scrollWidth+'px; '+
					'height: '+ (self.scrollHeight-heightGap)+'px;'+
					'left: '+ self.x+'px; '+
					'top: '+ self.y +'px;'+ 
					'padding-top: '+heightGap+'px">' +
					'<div><img src="'+$("base").attr("href")+'images/check.png"/>&nbsp;&nbsp;已选</div></div>'
				);
			}
		
		}
		else {
			if(orders[id] > 0){//之前加入购物车了
				orders[id] = -1;
				$("div #shadow"+id).remove();
			}
			else {
				orders[id] = id;
				$(self).parent().append(
					'<div id="shadow'+ id +'" class="home-shadow"style="position:absolute; '+
					'width: '+ self.scrollWidth+'px; '+
					'height: '+ (self.scrollHeight-heightGap)+'px;'+
					'left: '+ self.x+'px; '+
					'top: '+ self.y +'px;'+ 
					'padding-top: '+heightGap+'px">' +
					'<div><img src="'+$("base").attr("href")+'images/check.png"/>&nbsp;&nbsp;已选</div></div>'
				);
			}
		}
		var count = _count();
		$(".cart #number").text(count);
		if(count > 0){
			$(".cart").show();
		}
		else {
			$(".cart").hide();
		}
	}
	
	//头部点击事件（素材、荤菜、汤、土特团）
	function clickTypes(num){
		/*for(var i = 0; i < $(".types a").length; i++){
			$($(".types a")[i]).removeClass("active");
		}
		$(this).addClass("active");*/
		var url = baseUrl+"ajax/home/"+num;
		if(num == 3){//土特团
			$.ajax({
				url: url,
				success: function(data){
					console.log(data)
					var data 	= eval("("+data+")");
					var divs		= '';
					for(var r in data){
						var div = '<div id="i" class="special" style="width:95%" name="'+ data[r].Tutetuan.id+'"><div class="title">'+
							'<p>' + data[r].Tutetuan.name +
							'</p><span style="margin-right:0;float:right;font-size: 13px;line-height: 13px;">'+data[r].Tutetuan.time+
							'配送</span></div><img class="item-image" style="height:210px;" src="'+ data[r].Tutetuan.picurl +'" />' +
							'<span id="tutetuan-detail" name="'+ data[r].Tutetuan.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></span>' +
							'<span class="price"><img style="width: 10px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ data[r].Tutetuan.price.replace(/[^0-9]/ig,"") +'</span>'+
							'<span class="weight"><img style="width: 15px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+data[r].Tutetuan.number+'人起团</span></div>';
						divs+=div;
					}
					$(".items div").remove();
					$(".items").append(divs);
					
					var count = _count();
					$(".cart #number").text(count);
					if(count > 0){
						$(".cart").show();
					}
					else {
						$(".cart").hide();
					}
					setShadow();
				}
			});
		}
		else {
			$.ajax({
				url: url,
				success: function(data){
					var data 		= eval("("+data+")");
					var common 		= data.common;
					var special		= data.special;
					var recommend	= data.recommend;
					var divs		= '';
					
					for(var r in recommend){
						var div = '<div id="i" class="special" name="'+ recommend[r].Cookbook.id+'"><div class="title">'+
							'<span>今日推荐：</span><p>' + recommend[r].Material.name +
							'</p></div><img class="item-image" src="'+ recommend[r].Material.picurl +'" />' +
							'<span name="'+ recommend[r].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></span>' +
							'<span class="price"><img style="width: 10px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ recommend[r].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
							'<span class="weight"><img style="width: 15px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ recommend[r].Material.volume +'人份</span></div>';
						divs+=div;
					}
					for(var s in special){
						var div = '<div id="i" class="special" name="'+ special[s].Cookbook.id+'"><div class="title">'+
							'<span>今日特价：</span><p>' + special[s].Material.name +
							'</p></div><img class="item-image" src="'+ special[s].Material.picurl +'" />' +
							'<span name="'+ special[s].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></span>' +
							'<span class="price"><img style="width: 10px;margin-right:5px" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ special[s].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
							'<span class="weight"><img style="width: 15px;margin-right:5px" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ special[s].Material.volume +'人份</span></div>';
						divs+=div;
					}		
					for(var c in common){
						var div = '<div id="i" class="single" name="'+ common[c].Cookbook.id+'"><div class="title">'+
							common[c].Material.name +
							'</div><img class="item-image" src="'+ common[c].Material.picurl +'" />' +
							'<span class="price"><img style="width: 10px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ common[c].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
							'<span class="weight"><img style="width: 15px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ common[c].Material.volume +'人份</span>'+
							'<div name="'+ common[c].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></div></div>';
						divs+=div;
					}
					$(".items div").remove();
					$(".items").append(divs);
					
					var count = _count();
					$(".cart #number").text(count);
					if(count > 0){
						$(".cart").show();
					}
					else {
						$(".cart").hide();
					}
					setShadow();
				//	itemClick();
				}
			});	
		}
	}
	
	//页面加载完，调用了次方法，进来默认选中“荤菜”
	function clickHuncai(){
		var url = $("base").attr("href")+"ajax/home/1";
		$.ajax({
			url: url,
			success: function(data){
				var data 		= eval("("+data+")");
				var common 		= data.common;
				var special		= data.special;
				var recommend	= data.recommend;
				var divs		= '';
				
				for(var r in recommend){
					var div = '<div id="i" class="special" name="'+ recommend[r].Cookbook.id+'"><div class="title">'+
						'<span>今日推荐：</span><p>' + recommend[r].Material.name +
						'</p></div><img class="item-image" src="'+ recommend[r].Material.picurl +'" />' +
						'<span style="cursor:pointer" name="'+ recommend[r].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></span>' +
						'<span class="price"><img style="width: 10px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ recommend[r].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
						'<span class="weight"><img style="width: 15px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ recommend[r].Material.volume +'人份</span></div>';
					divs+=div;
				}
				for(var s in special){
					var div = '<div id="i" class="special" name="'+ special[s].Cookbook.id+'"><div class="title">'+
						'<span>今日特价：</span><p>' + special[s].Material.name +
						'</p></div><img class="item-image" src="'+ special[s].Material.picurl +'" />' +
						'<span name="'+ special[s].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></span>' +
						'<span class="price"><img style="width: 10px;margin-right:5px" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ special[s].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
						'<span class="weight"><img style="width: 15px;margin-right:5px" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ special[s].Material.volume +'人份</span></div>';
					divs+=div;
				}		
				for(var c in common){
					var div = '<div id="i" class="single" name="'+ common[c].Cookbook.id+'"><div class="title">'+
						common[c].Material.name +
						'</div><img class="item-image" src="'+ common[c].Material.picurl +'" />' +
						'<span class="price"><img style="width: 10px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/rmb@2x.png"/>'+ common[c].Material.price.replace(/[^0-9]/ig,"") +'</span>' +
						'<span class="weight"><img style="width: 15px;margin-right:5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/bow@2x.png"/>'+ common[c].Material.volume +'人份</span>'+
						'<div name="'+ common[c].Cookbook.id+'" class="detail">详情<img style="width:8px;margin-left: 5px;margin-top:-5px;" src="'+$("base").attr("href")+'img/greentri@2x.png"/></div></div>';
					divs+=div;
				}
				$(".items div").remove();
				$(".items").append(divs);
				
				var count = _count();
				$(".cart #number").text(count);
				if(count > 0){
					$(".cart").show();
				}
				else {
					$(".cart").hide();
				}
			//	setShadow();
			//	itemClick();
			}
		});
	}
	
	$(document).on("click", "#home-items .home-shadow", shadow);//列表图片上的阴影选中效果图片的点击事件
	$(document).on("click", "#home-items .item-image", shadow);//列表图片的点击事件
	
	//购物车页面 提交个人信息
	$("#registration-form-submit").click(function(){
		//$(".header").hide();
		//alert($("base").attr("href")+'wechat/register/'+$("#wechat_id").val());
		//console.log($(".registration-form #name").val());
		//console.log($(".registration-form #phone").val());
		//console.log($(".registration-form #location").val());
		if($(".registration-form #name").val() == '' ||
		   $(".registration-form #phone").val() == '' ||
		   $(".registration-form #location").val() == ''){
		   alert2("请填写完整信息!");
		}
		else if($(".registration-form #phone").val().length != 11){
			alert2("手机号码不正确");
		}
		else {
			$.ajax({
				url: $("base").attr("href")+'wechat/register/'+$("#wechat_id").val(),
				type: "POST",	
				data: {
					name: $(".registration-form #name").val(),
					phone: $(".registration-form #phone").val(),
					location: $(".registration-form #location").val()
				},
				success: function(data){
					//console.log(data);
					var data = eval("("+data+")");
					$.ajax({
						url: $("base").attr("href")+"/ajax/userRegister/"+$("#wechat_id").val(),
					});
					if(data.code=="success"){
						alert2("修改成功");
						if(data.Customer){
							$(".location #name").text(data.Customer.name);
							$(".location #phone").text(data.Customer.phone);
							$(".location #location").text(data.Customer.location);
							userStatus=1;
							$(".registration-form").hide();
						}
					}
					else {
						alert2("请填写完整信息.");
						//$(".registration-form").hide();
					}
					//$("#cart-header").show();
				}
			});
		}
	});
	
	//返回按钮点击事件
	// Home page Item click
	$(document).on("click", " .back img", function(){	
		//console.log(history);
		currentPage 	= history.pop();
		oldPage			= history[history.length-1];
		$(currentPage.id).hide();
		$(currentPage.header).hide();
		$(oldPage.id).show();
		$(oldPage.header).show();
		
		$("#menu-account").show();
		$("#menu-today").show();
		$("#menu-about").show();
		$("#menu-feedback").show();
		$("#menu-mylist").show();
				
		var count = _count();
		setShadow();
		
		//alert(oldPage.header);
		if(oldPage.header == "#home-header" ||
			oldPage.header == "#detail-header"){
			$(".cart #number").text(count);
			if(count > 0){
				$(".cart").show();
			}
		}
		else {
			$(".cart").hide();
		}
		//setShadow();
	});
	
	// Search click
	/*
	$(document).on("click", ".search img", function(){	
		history.push({
			url: window.location,
			page: 'search-page',
			id: '#search-page',
			header: '#search-header',
			time: new Date(),
			itemId: $(this).attr("name"),
		});
		$("#home-header").hide();
		$("#home-items").hide();
		$("#search-header").show();
		$("#search-page").show();
	});
	*/
	
	//在列表页面，点击“详情”响应事件，大块样式
	$(document).on("click" ,".special span.detail", function(){
		if(this.id == "tutetuan-detail"){
			tuanDetailGet($(this).attr("name"));
		}
		else {
			itemDetailGet($(this).attr("name"));
		}
		history.push({
			url: window.location,
			page: 'detail-item',
			id: '#detail-item',
			header: '#detail-header',
			time: new Date(),
			itemId: $(this).attr("name"),
		});
		$("#home-header").hide();
		$("#home-items").hide();
		$("#detail-header").show();
		$("#detail-item").show();
		
		
		var count = _count();
		$(".cart #number").text(count);
		if(count > 0){
			$(".cart").show();
		}
		else {
			$(".cart").hide();
		}
		
	});
	
	//在列表页面，点击“详情”响应事件，小块样式
	$(document).on("click", ".single .detail", function(){
		itemDetailGet($(this).attr("name"));
		history.push({
			url: window.location,
			page: 'detail-item',
			id: '#detail-item',
			header: '#detail-header',
			time: new Date(),
			itemId: $(this).attr("name")
		});
		$("#home-header").hide();
		$("#home-items").hide();
		$("#detail-header").show();
		$("#detail-item").show();
		
		
		var count = _count();
		$(".cart #number").text(count);
		if(count > 0){
			$(".cart").show();
		}
		else {
			$(".cart").hide();
		}
		
	});
	
	//详情页面，下单按钮点击事件
	$("#detail-item #order").click(function(){
		$(".cart").hide();
		var id = $("#detail-item-id").val();
		
		var types = $("#detail-header-name").attr("name");
		if(types == "tutetuan")
			tutetuans[id] = id;
		else 
			orders[id] = id;
		
		cartDetailGet();		
		
		history.push({
			url: window.location,
			page: 'cart-items',
			id: '#cart-items',
			header: '#cart-header',
			time: new Date()
		});
		$("#detail-header").hide();
		$("#detail-item").hide();
		$("#cart-header").show();
		$("#cart-items").show();
	});
	
	//悬浮的购物车图标，点击事件
	$("div.cart").click(function(){
		$(".cart").hide();
		
		cartDetailGet();
		history.push({
			url: window.location,
			page: 'cart-items',
			id: '#cart-items',
			header: '#cart-header',
			time: new Date()
		});
		
		$("#home-header").hide();
		$("#home-items").hide();
		$("#detail-header").hide();
		$("#detail-item").hide();
		$("#cart-header").show();
		$("#cart-items").show();
	});
	
	//cart click,在详情页面，点击“加入购物车”按钮
	$("#cart").bind('click', function(){
		$(".cart").hide();
		alert("QQQQQQQQQQQ");
		var id = $("#detail-item-id").val();
		var types = $("#detail-header-name").attr("name");
		if(types == "tutetuan")
			tutetuans[id] = id;
		else 
			orders[id] = id;
			console.log("orders:"+orders);
			//orders.push(id);
		var count = _count();
		$(".cart #number").text(count);
		if(count > 0){
			$(".cart").show();
		}
		else {
			$(".cart").hide();
		}
	});
	
	//购物车页面，“删除”点击事件
	$(document).on("click", ".item-remove", function(){
		$(this).parent().remove();

		var wechat_id = $("#wechat_id").val();
		var tutetuan = $(this).parent().attr("name");
		var item_id	= $(this).attr("name");
		var price = $("#priceofid"+item_id).val();
		if(tutetuan == "tutetuan"){
			tutetuans[item_id] = -1;
		}
		else {
			orders[item_id] = -1;
		}
		//console.log(orders);
		cartDetailGet();
		
		/*
		var wechat_id = $("#wechat_id").val();
		var item_id	= $(this).attr("name");
		var price = $("#priceofid"+item_id).val();
		orders[item_id] = -1;
		var _prices = Array();
		$(".item input").each(function(){
			_prices.push(parseFloat(this.value));
		});
		_prices.sort(function(x,y){return (y)-(x);}); 
		total = 0;
		var total_all = 0;
		var j = 0;
		var counter = 0;
		for(var i in _prices){
			counter ++;
			total_all += _prices[i];
			if(j++ < _prices.length - (_prices.length/3)){
				total+= (_prices[i]);
			}
		}
		if(count <= 0){	
			$("#cart-items #total").text(total-5);
			$("#cart-items #total-all").text(total);
			if(total-5 >= 25)
				$("#cart-items .advanced").text("享受新用户立减5元并获得6元优惠券下次使用");
			else 
				$("#cart-items .advanced").text("第一次下单, 立减五元");
			$("#cart-items .advanced").show();
		}
		else if(discount == 1){
			$("#cart-items #total").text(total-6);
			$("#cart-items #total-all").text(total);
			$("#cart-items .advanced").text("使用6元优惠券一张");
			$("#cart-items .advanced").show();
		}
		else if(total >= 25){
			$("#cart-items #total").text(total);
			$("#cart-items .advanced").text("获得6元消费券一张");
			$("#cart-items .advanced").show();
		}
		else {
			$("#cart-items #total").text(total);
			$("#cart-items .advanced").show("消费满25元即可获得6元优惠券一张下次使用");
		}
		
		
		//alert(total);
		$(".amount #total").text(total);
		$(".amount #total-all").text(total_all);
		/*
		var wechat_id = $("#wechat_id").val();
		var item_id	= $(this).attr("name");
		var price = $("#priceofid"+item_id).val();
		orders[item_id] = -1;
		console.log(orders);
		var price2 = Array();
		var flag = true;
		for(var i in prices){
			if(prices[i] == price && flag){
				flag = false;
			}
			else {
				price2.push(prices[i]);
			}
		}
		
		price2.sort(function(x,y){return parseFloat(y)-parseFloat(x);}); 
		//console.log(prices.length/3);
		total = 0;
		var j = 0;
		for(var i in price2){
			if(j++ < price2.length - (price2.length/3)){
				total+= parseFloat(price2[i]);
			}
		}
		$(".total #total").text(total);
		$(this).parent().remove();
		//var url = $("base").attr("href")+'ajax/cartItemRemove/'+ item_id +'/'+wechat_id;
		*/
	});
	
	// Home Header click
	/*
	$(".types a").each(function(){
		$(this).click(function(){
			$(".types a").each(function(){
				$(this).removeClass("active");
			});
			$(this).addClass("active");
		});
	});
	*/
	
	//头部点击事件（素材、荤菜、汤、土特团）
	// Home Header Click
	//$(".types a").bind("click",  clickTypes)
	
	//在购物车页面，提交订单，点击事件
	$("#order-submit").click(function(){
		var counter = _count();
		var wechat_id = $("#wechat_id").val();
		console.log(wechat_id);
		if(new Date().getDay() == 5 || new Date().getDay() == 6){
			alert2("周五周六不能下单");
		}
		else if(counter == 0){
			alert2("至少选择一件菜品");
		}
		else {
			$(".cart").hide();
			var wechat_id = $("#wechat_id").val();
			if(userStatus == 0){
				$(".registration-form").show();
			}
			else {
				var url = $("base").attr("href")+'ajax/cartOrder/'+wechat_id;
				console.log(tutetuans);
				//$(".item[name='tutetuan'] label").each(function(){console.log($(this).text()); console.log($(this).attr("id"))});
				var labels = $(".item[name='tutetuan'] label");
				var numbers = Array();
				for(var i = 0; i < labels.length; i++){
					var id = labels[i].id.split("numberofid")[1];
					var num = $(labels[i]).text();
					numbers[id] = num;
				}
				//console.log(numbers);
				//return ;
				if(orders.length > 0 || tutetuans.length > 0){
					$.ajax({
						url: url,
						data: { ids: orders , tuan_ids: tutetuans, numbers: numbers},
						success: function(data){
							log = data;
							// Clear all orders
							orders = Array();
							console.log(data);
							var data = eval("("+data+")");
							orderResultSet(data);
							
							history.push({
								url: window.location,
								page: 'report-page',
								id: '#report-page',
								header: '#report-header',
								time: new Date()
							});
							$("#cart-header").hide();
							$("#cart-items").hide();
							$("#report-header").show();
							$("#report-page").show();
						}
					});
				}
				else{
					//alert("请至少选择一道菜呀");
				}
			}
		}
		
		/*
		
		$.ajax({
			url: url,
			success: function(data){
				alert(data);
			}
		});
		*/
	});
	
	$(".location #modify").click(function(){
		$(".registration-form").css("height", $("#cart-items").css("height")+30);
		$(".registration-body").css("position", "fixed");
		$(".registration-form").show();
	});
	
	$("#registration-form-cancel").click(function(){
		$(".registration-form").hide();
	});
	
	$("#report-page #goaround").click(function(){
		prices = Array();
		orders_total = Array();
		orders_total_result = 0;
		orders = Array();
		tutetuans = Array();
		clearShadow();
		//setShadow();
		history.length = 0;
		history.push({
			url: window.location,
			page: 'home',
			id: '#home-items',
			header: '#home-header',
			time: new Date()
		});
		$("#report-header").hide();
		$("#report-page").hide();
		
		$("#home-header").show();
		$("#home-items").show();
		$(".cart").hide();
	});
	
	//头部右上角的“菜单项”点击事件
	$(".menu").click(function(){
		//$(".cart").hide();
		if($("#menu-shadow").css("display") == "block"){
			$("#menu-shadow").hide();
		}
		else {
			$("#menu-shadow").show();
		}
	});
	
	//“今日菜谱”点击事件
	$("#menu-today").click(function(){
		$("#menu-shadow").hide();
		
		$("#menu-account").show();	
		$("#menu-today").show();
		$("#menu-about").show();
		$("#menu-feedback").show();
		$("#menu-mylist").show();
		
		history = Array();
		history.push({
			url: window.location,
			page: 'home',
			id: '#home-items',
			header: '#home-header',
			time: new Date()
		});
		
		//clickSucai();
		clearShadow();//此处发现bug，被选进购物车的菜，的选中效果（阴影）不见了
		
		$("#account-header").hide();
		$("#account-page").hide();		
		$("#about-page").hide();
		$("#about-header").hide();
		$("#feedback-page").hide();
		$("#feedback-header").hide();
		$("#mylist-page").hide();
		$("#mylist-header").hide();
		
		$("#detail-header").hide();
		$("#detail-items").hide();
		$("#cart-header").hide();
		$("#cart-items").hide();
		$("#search-header").hide();
		$("#search-page").hide();
		$("#report-header").hide();
		$("#report-page").hide();
		
		$("#home-header").show();
		$("#home-items").show();
	});
	
	$("#menu-shadow").click(function(){
		$("#menu-shadow").hide();
	});
	
	$("#menu-account").click(function(){
		$("#menu-account").hide();	
		$("#menu-today").show();
		$("#menu-about").show();
		$("#menu-feedback").show();
		$("#menu-shadow").hide();
		$("#menu-mylist").show();
		
		if( history[history.length-1].page != "accbout-page" ||
			history[history.length-1].page != "about-page" ||
			history[history.length-1].page != "feedback-page"||
			history[history.length-1].page != "mylist-page"
		){
			$(history[history.length-1].header).hide();
			$(history[history.length-1].id).hide();
			
			history.push({
				url: window.location,
				page: 'account-page',
				id: '#account-page',
				header: '#account-header',
				time: new Date()
			});
		}
		$("#account-header").show();
		$("#account-page").show();
		
		$("#about-page").hide();
		$("#about-header").hide();
		$("#feedback-page").hide();
		$("#feedback-header").hide();
		$("#mylist-page").hide();
		$("#mylist-header").hide();
		
		// not menu pages
		$("#detail-header").hide();
		$("#detail-items").hide();
		$("#cart-header").hide();
		$("#cart-items").hide();
		$("#search-header").hide();
		$("#search-page").hide();
		$("#report-header").hide();
		$("#report-page").hide();		
		$("#home-header").hide();
		$("#home-items").hide();
	});
	
	$("#menu-about").click(function(){
		$("#menu-account").show();	
		$("#menu-today").show();
		$("#menu-about").hide();
		$("#menu-feedback").show();
		$("#menu-shadow").hide();
		$("#menu-mylist").show();
		
		if( history[history.length-1].page != "accbout-page" ||
			history[history.length-1].page != "about-page" ||
			history[history.length-1].page != "feedback-page"||
			history[history.length-1].page != "mylist-page"
		){
			$(history[history.length-1].header).hide();
			$(history[history.length-1].id).hide();
			
			history.push({
				url: window.location,
				page: 'about-page',
				id: '#about-page',
				header: '#about-header',
				time: new Date()
			});
		}
		$("#about-page").show();
		$("#about-header").show();
		
		$("#feedback-page").hide();
		$("#feedback-header").hide();
		
		$("#account-header").hide();
		$("#account-page").hide();
		$("#mylist-page").hide();
		$("#mylist-header").hide();
		
		
		$("#detail-header").hide();
		$("#detail-items").hide();
		$("#cart-header").hide();
		$("#cart-items").hide();
		$("#search-header").hide();
		$("#search-page").hide();
		$("#report-header").hide();
		$("#report-page").hide();		
		$("#home-header").hide();
		$("#home-items").hide();
	});
	
	$("#menu-feedback").click(function(){
		$("#menu-account").show();	
		$("#menu-today").show();
		$("#menu-about").show();
		$("#menu-feedback").hide();
		$("#menu-shadow").hide();
		$("#menu-mylist").show();
		
		if( history[history.length-1].page != "accbout-page" ||
			history[history.length-1].page != "about-page" ||
			history[history.length-1].page != "feedback-page" ||
			history[history.length-1].page != "mylist-page"
		){
			$(history[history.length-1].header).hide();
			$(history[history.length-1].id).hide();
			
			history.push({
				url: window.location,
				page: 'feedback-page',
				id: '#feedback-page',
				header: '#feedback-header',
				time: new Date()
			});
		}
		$("#feedback-page").show();
		$("#feedback-header").show();
		
		$("#account-header").hide();
		$("#account-page").hide();
		$("#about-page").hide();
		$("#about-header").hide();
		$("#mylist-page").hide();
		$("#mylist-header").hide();
		
		
		$("#detail-header").hide();
		$("#detail-items").hide();
		$("#cart-header").hide();
		$("#cart-items").hide();
		$("#search-header").hide();
		$("#search-page").hide();
		$("#report-header").hide();
		$("#report-page").hide();		
		$("#home-header").hide();
		$("#home-items").hide();
	});
	
	$("#menu-mylist").click(function(){
		$("#menu-account").show();	
		$("#menu-today").show();
		$("#menu-about").show();
		$("#menu-feedback").show();
		$("#menu-shadow").hide();
		$("#menu-mylist").hide();
		
		if( history[history.length-1].page != "accbout-page" ||
			history[history.length-1].page != "about-page" ||
			history[history.length-1].page != "feedback-page" ||
			history[history.length-1].page != "mylist-page"
		){
			$(history[history.length-1].header).hide();
			$(history[history.length-1].id).hide();
			
			history.push({
				url: window.location,
				page: 'mylist-page',
				id: '#mylist-page',
				header: '#mylist-header',
				time: new Date()
			});
		}
		$("#mylist-page .item").remove();
		
		orders_total_result = 0;
		$.ajax({
			url: $("base").attr("href")+'ajax/orders/'+$("#wechat_id").val(),
			success: function(data){
				var data = eval("("+data+")");
				//console.log(data);
				tuan = data.tuan;
				var tuan_price = 0;
				console.log(tuan);
				for(var t in tuan){
					for(var tt in tuan[t]){
						var div = '<span class="time" style="padding-left: 10px; color:green">您于'+get_time(t*1000)+'参与了团购活动</span>'+
											'<p style="padding-left: 10px">'+tuan[t][tt].name+' 价格:'+tuan[t][tt].price+' 份量：'+ tuan[t][tt].fenliang +'</p>' +
											'<div class="border"></div>';
						$(".mylist-items .tuan").append(div);
					}
				}
				data = data.cart;
				for(var j in data){
					orders_total = Array();
					var div = '<div class="item"><div class="time">您于 <span class="create_at">'+
								get_time(j*1000)+' </span>购买了以下商品</div>';
					for(var i in data[j]){
						div +='<div class="info"><span class="name">'
									+data[j][i].Material.name + '</span><span class="price">'
									+data[j][i].Material.price + '元 '
									+data[j][i].Material.volume + '人份</span></div>';
						
						orders_total.push(parseFloat(data[j][i].Material.price.replace(/[^0-9]/ig,"")));
					}
					// 计算得到所有的数值
					orders_total_result = 0;
					var total_all = 0;
					orders_total.sort(function(x,y){return y-x;}); 
					
					var k = 0;
					for(var i in orders_total){
						total_all += orders_total[i];
						if(k++ < orders_total.length - (orders_total.length/3)){
							orders_total_result += orders_total[i];
						}
					}
					// (1374000000000 : Wed Jul 17 2013 02:40:00 GMT+0800 (中国标准时间)
					if(j*1000 <= 1374000000000){
						//console.log(j*1000)
						/**
						 * 原满三免一逻辑
						 */						
						div += '<div style="color:green"><span id="total-all">合计:' + total_all +'</span>元</span>' +
								 '&nbsp;&nbsp;实收<span id="total">'+ orders_total_result +'</span>元';						
						var counter = 0;
						for(var i in orders_total){counter ++;}
						if(counter >= 3){
							div += '<span class="advanced">(享受满3免1优惠)</span>';
						}
						div += '</div>';
								 
						div += '<div class="border"></div></div>';
						$(".mylist-items").append(div);
					}
					else {
						/**
						 * 第一次下单立刻减五元
						 
						var huodong = orders_total_result;
						if(data[j][i].Cart.status == 2){
							huodong = orders_total_result-5;							
							div += '<div style="color:green"><span id="total-all">合计:' + total_all +'</span>元</span>' +
									 '&nbsp;&nbsp;实收<span id="total">'+ (total_all-5) +'</span>元';	
							div += '<span class="advanced">(第一次下单, 立减五元)</span>';
							div += '</div>';
									 
							div += '<div class="border"></div></div>';
						}
						else 
						*/
						// 日期：20130819 之后优惠券暂时不发放 时间戳： 1376928000000
						var youhuiquan_end_date = 1376928000000;
						if(data[j][i].Cart.discount_id != 0){		
							div += '<div style="color:green"><span id="total-all">合计:' + total_all +'</span>元</span>' +
									 '&nbsp;&nbsp;实收<span id="total">'+ (total_all-6)+'</span>元';	
							div += '<span class="advanced">(使用6元优惠券)</span>';
							div += '</div>';
							div += '<div class="border"></div></div>';
						}
						else if(orders_total_result >= 25 && new Date().getTime() < youhuiquan_end_date){
							div += '<div style="color:green"><span id="total-all">合计:' + total_all +'</span>元</span>' +
									 '&nbsp;&nbsp;实收<span id="total">'+ total_all +'</span>元';	
							div += '<span class="advanced">(购满25元, 送6元优惠券)</span>';
							div += '</div>';
							div += '<div class="border"></div></div>';
						}
						else {
							div += '<div style="color:green"><span id="total-all">合计:' + total_all +'</span>元</span>' +
									 '&nbsp;&nbsp;实收<span id="total">'+ total_all +'</span>元';	
							div += '</div>';
							div += '<div class="border"></div></div>';
						}
						$(".mylist-items").append(div);
					}
					
					
					orders_total.sort(function(x,y){return y-x;}); 					
					var j = 0;
					for(var i in orders_total){
						if(j++ < orders_total.length - (orders_total.length/3)){
							orders_total_result += orders_total[i];
						}
					}
				}
			}
		});
		
		$("#mylist-page").show();
		$("#mylist-header").show();
		
		$("#detail-header").hide();
		$("#detail-item").hide();
		
		$("#account-header").hide();
		$("#account-page").hide();
		$("#about-page").hide();
		$("#about-header").hide();
		$("#feedback-page").hide();
		$("#feedback-header").hide();
		
		
		$("#detail-header").hide();
		$("#detail-items").hide();
		$("#cart-header").hide();
		$("#cart-items").hide();
		$("#search-header").hide();
		$("#search-page").hide();
		$("#report-header").hide();
		$("#report-page").hide();		
		$("#home-header").hide();
		$("#home-items").hide();
	});
	
	$("#feedback-page #feedback-submit").click(function(){
		var content = $("#feedback-page .content").val();
		if(content != ""){		
			$.ajax({
				url: $("base").attr("href")+'ajax/feedback/'+$("#wechat_id").val(),
				data: {content: content},
				success: function(data){
					$("#feedback-form").hide();
					$("#feedback-result").show();
					//alert(data)
				}
			});
		}
	});
	
	function get_time(t) 
	{ 
		var date=new Date(t); 
		var year="",month="",day="",week="",hour="",minute="",second=""; 
		year=date.getFullYear(); 
		month=add_zero(date.getMonth()+1); 
		day=add_zero(date.getDate()); 
		week=date.getDay(); 
		switch (date.getDay()) { 
			case 0:val="星期天";break 
			case 1:val="星期一";break 
			case 2:val="星期二";break 
			case 3:val="星期三";break 
			case 4:val="星期四";break 
			case 5:val="星期五";break 
			case 6:val="星期六";break 
		} 
		hour=add_zero(date.getHours()); 
		minute=add_zero(date.getMinutes()); 
		second=add_zero(date.getSeconds()); 
		//timetable.innerText
		return " "+year+"."+month+"."+day+" "+hour+":"+minute+":"+second+" "+ val; 
	}
	 
	//取得用户的个人呢信息（ 初始化时就获取）
	function getCustomerInfo(){
		$.ajax({
			url: $("base").attr("href")+'ajax/getCustomerInfo/'+$("#wechat_id").val(),
			success: function(data){
				var data = eval("("+data+")");
				//console.log(data);
				if(data.Customer){
					$(".customer-name").each(function(){
						$(this).text(data.Customer.name);
						$(this).val(data.Customer.name);
					});
					$(".customer-phone").each(function(){
						$(this).text(data.Customer.phone);
						$(this).val(data.Customer.phone	);
					});
					$(".customer-location").each(function(){
						$(this).text(data.Customer.location);
						$(this).val(data.Customer.location);
					});
					userStatus = data.Customer.status;
					//console.log(userStatus);
					//userStatus = 1;
				}
			}
		});
	}
	 
	function add_zero(temp) 
	{ 
		if(temp<10)
			return "0"+temp; 
		else 
			return temp; 
	} 
	
	// Judge whether they are selected
	//document.onreadystatechange = setShadow();
	
	//clickSucai();  1372217124694 
	//				 1372207435000
	//clickHuncai();
	//getCustomerInfo();
//});